<?php session_start(); ?>
<!DOCTYPE HTML>
<html>
	
<head>
	<title>Stewie's Market</title>
	<link rel="stylesheet" href="cs2102.css">

	<script type="text/javascript">

	function valAtLeastOneRadioButton(btn) {
		var cnt = -1;
		for (var i=btn.length-1; i > -1; i--) {
			if (btn[i].checked) {cnt = i; i = -1;}
		}
		if (cnt > -1) return btn[cnt].value;
		else return null;
	}

	function validateForm()
	{
		var title = document.forms["submit_item"]["title"].value;
		var category_btn = document.forms["submit_item"]["category"];
		var request_btn = document.forms["submit_item"]["request"];
		var condition_btn = document.forms["submit_item"]["condition"];
		var price = document.forms["submit_item"]["price"].value;
		if (title == null || title == "")
		{
			alert("You have to give the ad a title");
			return false;
		}
		if (valAtLeastOneRadioButton(category_btn) == null)
		{
			alert("You have to select a category");
			return false;
		}
		if (valAtLeastOneRadioButton(request_btn) == null)
		{
			alert("You have to select a request type");
			return false;
		}
		if (valAtLeastOneRadioButton(condition_btn) == null)
		{
			alert("You have to select an item condition");
			return false;
		}
		if (!/^\d+$/.test(price) && price != "")
		{
			alert("The price has to be a number");
			return false;
		}
		return true;
	}

	function setRadioValue(name, value)
	{

	}
	</script>
</head>

<body>
<div class="container">
	<!-- Site navigation menu -->
	<?php include 'nav.php'; ?>

	<!-- Main content -->
	<br /><h1>Submit an ad to Stewie's Market</h1>

	<p>Add an ad using the form below.</p>
	<div class = "boxed">
	<form action="submitform.php" method="get" name="submit_item" onsubmit="return validateForm()">
		<img src = "Title.png">
		 <input type="text" name="title" placeholder="Object title" size="40"><br> 

		<br>Description:<br>
		<div class="boxes">
			<textarea rows="4" cols="35" placeholder="Enter description here..." name="description">
		</textarea><br><br>
		</div>
	</div>
		<div class = "boxed">
		<img src="SearchHeader2.png" alt="I want to">
		<div class="boxes">
			<input type="radio" name="category" value="Clothes" onclick="setRadioValue(this.name, this.value)"> Clothes<br>
			<input type="radio" name="category" value="Electronics"> Electronics<br>
			<input type="radio" name="category" value="Furniture"> Furniture<br>
			<input type="radio" name="category" value="Stationary"> Stationary<br>
			<input type="radio" name="category" value="Furniture"> Furniture<br>
			<input type="radio" name="category" value="Kitchenware"> Kitchenware<br>
			<input type="radio" name="category" value="Books"> Books<br>
			<input type="radio" name="category" value="Others"> Others<br>
		</div>
	</div>
		<div class = "boxed">
		<img src="SearchHeader1.png" alt="I want to">
		<div class="boxes">
			<input type="radio" name="request" value="Buy"> Buy<br>
			<input type="radio" name="request" value="Sell"> Sell<br>
			<input type="radio" name="request" value="Trade"> Trade<br>
		</div>
	</div>
		<div class = "boxed">
		<img src = "Age.png">
		<div class="boxes">
			<input type="text" name="years_of_use" size="20"><br>
		</div>
	</div>
	<div class = "boxed">
		<img src = "Price.png">
		<div class="boxes">
			<input type="text" name="price" size="10"><br>
		</div>
		</div>
		<div class = "boxed">
		<img src = "Condition.png">
		<div class="boxes">
			<input type="radio" name="condition" value="As new"> As new<br>
			<input type="radio" name="condition" value="Good"> Good<br>
			<input type="radio" name="condition" value="Worn out"> Worn out<br>
			<input type="radio" name="condition" value="Defect"> Defect<br>
		</div>
		<br>
	</div>
		<input type="submit" value="Submit">
	</form>

	<!-- Sign and date the page, it's only polite! -->
	<address>Made by Project group 31 for CS2102, NUS 2013.</address>
</div>
</body>

</html>
